package com.demonzym.gtv.view;

import io.vov.vitamio.widget.VideoView;
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;

public class GVideoView extends VideoView {
	private static final String TAG = "GVideoView";
	//DISPLAY MODE
	public static final int DISPLAY_MODE_DEFAULT = 0;
	public static final int DISPLAY_MODE_FULLSCREEN = 1;
	public static final int DISPLAY_MODE_CUSTOM = 2;
	//Custom size
	private int mCustomWidth = -1;
	private int mCustomHeight = -1;

	private int mDisplayMode = DISPLAY_MODE_FULLSCREEN;

	public GVideoView(Context context) {
		this(context, null, 0);
		// TODO Auto-generated constructor stub
	}

	public GVideoView(Context context, AttributeSet attrs) {
		this(context, attrs, 0);
		// TODO Auto-generated constructor stub
	}

	public GVideoView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		// TODO Auto-generated constructor stub
	}

	public void setDisplayMode(int mode) {
		if (mode < 0 || mode > 2)
			return;
		if(mode == mDisplayMode){
			if(mode != DISPLAY_MODE_CUSTOM){
				return;
			}else if(getMeasuredWidth() == mCustomWidth && getMeasuredHeight() == mCustomHeight){
				return;
			}
		}
		mDisplayMode = mode;
		requestLayout();
	}
	
	public int getDisplayMode(){
		return mDisplayMode;
	}

	public void setCustomSize(int width, int height) {
		mCustomWidth = width;
		mCustomHeight = height;
	}
	
	@Override
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		// TODO Auto-generated method stub
		Log.i(TAG, "onMeasure");
		int width = 0;
		int height = 0;
		switch (mDisplayMode) {
		case DISPLAY_MODE_CUSTOM:
			if (mCustomWidth > 0 && mCustomHeight > 0)
				setMeasuredDimension(mCustomWidth, mCustomHeight);
			else
				super.onMeasure(widthMeasureSpec, heightMeasureSpec);
			break;
		case DISPLAY_MODE_FULLSCREEN:
			width = MeasureSpec.getSize(widthMeasureSpec);
			height = MeasureSpec.getSize(heightMeasureSpec);
			setMeasuredDimension(width, height);
			break;
		case DISPLAY_MODE_DEFAULT:
		default:
			super.onMeasure(widthMeasureSpec, heightMeasureSpec);
			break;
		}
	}

}
